package com.ruoyi.sywx.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.sywx.domain.vo.YqUnitLinkVo;
import com.ruoyi.sywx.domain.bo.YqUnitLinkBo;
import com.ruoyi.sywx.service.IYqUnitLinkService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 舆情和涉情单位关联
 *
 * @author ruoyi
 * @date 2024-01-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/sywx/unitLink")
public class YqUnitLinkController extends BaseController {

    private final IYqUnitLinkService iYqUnitLinkService;

    /**
     * 查询舆情和涉情单位关联列表
     */
    @SaCheckPermission("sywx:unitLink:list")
    @GetMapping("/list")
    public TableDataInfo<YqUnitLinkVo> list(YqUnitLinkBo bo, PageQuery pageQuery) {
        return iYqUnitLinkService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出舆情和涉情单位关联列表
     */
    @SaCheckPermission("sywx:unitLink:export")
    @Log(title = "舆情和涉情单位关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(YqUnitLinkBo bo, HttpServletResponse response) {
        List<YqUnitLinkVo> list = iYqUnitLinkService.queryList(bo);
        ExcelUtil.exportExcel(list, "舆情和涉情单位关联", YqUnitLinkVo.class, response);
    }

    /**
     * 获取舆情和涉情单位关联详细信息
     *
     * @param yqId 主键
     */
    @SaCheckPermission("sywx:unitLink:query")
    @GetMapping("/{yqId}")
    public R<YqUnitLinkVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long yqId) {
        return R.ok(iYqUnitLinkService.queryById(yqId));
    }

    /**
     * 新增舆情和涉情单位关联
     */
    @SaCheckPermission("sywx:unitLink:add")
    @Log(title = "舆情和涉情单位关联", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody YqUnitLinkBo bo) {
        return toAjax(iYqUnitLinkService.insertByBo(bo));
    }

    /**
     * 修改舆情和涉情单位关联
     */
    @SaCheckPermission("sywx:unitLink:edit")
    @Log(title = "舆情和涉情单位关联", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody YqUnitLinkBo bo) {
        return toAjax(iYqUnitLinkService.updateByBo(bo));
    }

    /**
     * 删除舆情和涉情单位关联
     *
     * @param yqIds 主键串
     */
    @SaCheckPermission("sywx:unitLink:remove")
    @Log(title = "舆情和涉情单位关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{yqIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] yqIds) {
        return toAjax(iYqUnitLinkService.deleteWithValidByIds(Arrays.asList(yqIds), true));
    }
}
